package com.insurance.modules.claim.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.insurance.common.utils.PageUtils;
import com.insurance.common.utils.Query;
import com.insurance.modules.claim.constants.ClaimConstants;
import com.insurance.modules.claim.dao.SettlementCancelDao;
import com.insurance.modules.claim.entity.ClaimSettlementEntity;
import com.insurance.modules.claim.entity.SettlementCancelEntity;
import com.insurance.modules.claim.service.ClaimSettlementService;
import com.insurance.modules.claim.service.SettlementCancelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;


@Service("settlementCancelService")
public class SettlementCancelServiceImpl extends ServiceImpl<SettlementCancelDao, SettlementCancelEntity> implements SettlementCancelService {

    @Autowired
    private ClaimSettlementService claimSettlementService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SettlementCancelEntity> page = this.page(
                new Query<SettlementCancelEntity>().getPage(params),
                new QueryWrapper<>()
        );

        return new PageUtils(page);
    }

    @Override
    @Transactional
    public void saveAndChangeStatus(SettlementCancelEntity settlementCancel) {
        // 保存撤销记录
        this.save(settlementCancel);
        // 修改案件理赔表状态
        ClaimSettlementEntity claimSettlement = claimSettlementService.getById(settlementCancel.getCsId());
        claimSettlement.setCaseStatus(ClaimConstants.CLAIM_STATUS_CANCELLED);
        claimSettlementService.updateById(claimSettlement);
    }

}